package com.topisv.tms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.Function;
import com.topisv.tms.entity.QueryParamHolder;
import com.topisv.tms.repository.FunctionDao;
import com.topisv.tms.repository.RolepermDao;
import com.topisv.tms.repository.UserroleDao;
import com.topisv.tms.service.base.BaseService;

//Spring Bean的标识.
@Component
// 默认将类中的所有public函数纳入事务管理.
@Transactional(readOnly = true)
public class FunctionService extends BaseService{

	private FunctionDao functionDao;
	
	private UserroleDao userroleDao;
	
	private RolepermDao rolepermDao;

	public Function getFunction(Long id) {
		return functionDao.findOne(id);
	}

	@Transactional(readOnly = false)
	public void saveFunction(Function entity) {
		functionDao.save(entity);
	}

	@Transactional(readOnly = false)
	public void deleteFunction(Long id) {
		functionDao.delete(id);
	}

	public List<Function> getAllFunction() {
		return (List<Function>) functionDao.findAll();
	}
	
	public List<Function> getMenu(String key) {
		List<Function> functions = (List<Function>) functionDao.findByStatus(key);
		return functions;
	}
	
	public List<Function> getMenu(short restype,String key) {
		List<Function> functions = (List<Function>) functionDao.findMenu(restype,key);
		return functions;
	}

	public Page<Function> getFunction(QueryParamHolder paramHolder) {
		return findByJson(paramHolder, functionDao, Function.class);
	}

	@Autowired
	public void setFunctionDao(FunctionDao functionDao) {
		this.functionDao = functionDao;
	}
	@Autowired
	public void setUserroleDao(UserroleDao userroleDao) {
		this.userroleDao = userroleDao;
	}
	@Autowired
	public void setRolepermDao(RolepermDao rolepermDao) {
		this.rolepermDao = rolepermDao;
	}
}
